# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=responder
pkgver=v3.1.7.0.r8.g9a5e33a
pkgrel=1
epoch=4
pkgdesc='A LLMNR and NBT-NS poisoner, with built-in HTTP/SMB/MSSQL/FTP/LDAP rogue authentication server supporting NTLMv1/NTLMv2/LMv2 (multirelay version).'
groups=('blackarch' 'blackarch-scanner' 'blackarch-fuzzer' 'blackarch-spoof'
        'blackarch-networking')
arch=('any')
depends=('impacket' 'mingw-w64-gcc' 'python' 'python-aioquic'
         'python-cryptography' 'python-pycryptodome' 'python-netifaces')
makedepends=('git')
url='https://github.com/lgandx/Responder'
license=('GPL-3.0-or-later')
source=("$pkgname::git+https://github.com/lgandx/Responder.git")
sha512sums=('SKIP')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  cd "$pkgname/tools"

  x86_64-w64-mingw32-gcc ./MultiRelay/bin/Runas.c \
    -o ./MultiRelay/bin/Runas.exe -municode -lwtsapi32 -luserenv
  x86_64-w64-mingw32-gcc ./MultiRelay/bin/Syssvc.c \
    -o ./MultiRelay/bin/Syssvc.exe -municode
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  rm README.md LICENSE *.sh

  cp -a * "$pkgdir/usr/share/$pkgname/"

  # Responder
  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python Responder.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"

  # Responder DumpHash
  cat > "$pkgdir/usr/bin/$pkgname-dumphash" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python DumpHash.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-dumphash"

  # Responder Report
  cat > "$pkgdir/usr/bin/$pkgname-report" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python Report.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-report"

  # Responder DNSUpdate
  cat > "$pkgdir/usr/bin/$pkgname-dnsupdate" << EOF
#!/bin/sh
cd /usr/share/$pkgname/tools
exec python DNSUpdate.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-dnsupdate"

  # Responder FindSQLSrv
  cat > "$pkgdir/usr/bin/$pkgname-findsqlsrv" << EOF
#!/bin/sh
cd /usr/share/$pkgname/tools
exec python FindSQLSrv.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-findsqlsrv"

  # Responder ICMP-Redirect
  cat > "$pkgdir/usr/bin/$pkgname-icmp-redirect" << EOF
#!/bin/sh
cd /usr/share/$pkgname/tools
exec python Icmp-Redirect.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-icmp-redirect"

  # Responder Multirelay
  cat > "$pkgdir/usr/bin/$pkgname-multirelay" << EOF
#!/bin/sh
cd /usr/share/$pkgname/tools
exec python MultiRelay.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-multirelay"

  # Responder RunFinger
  cat > "$pkgdir/usr/bin/$pkgname-runfinger" << EOF
#!/bin/sh
cd /usr/share/$pkgname/tools
exec python RunFinger.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-runfinger"

  # Responder's Impacket secretsdump
  cat > "$pkgdir/usr/bin/$pkgname-secretsdump" << EOF
#!/bin/sh
cd /usr/share/$pkgname/tools/MultiRelay/impacket-dev
exec python secretsdump.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname-secretsdump"
}

